﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Web;


namespace lxwmvc
{
    /// <summary>
    /// [09.4.10 lxw]<para />
    /// </summary>
    public class powerhelper : basehelper
    {
        /// <summary>
        /// 功能:判断是否具有访问制定ID的权限
        /// [09.4.12 lxw]<para />
        /// </summary>
        /// <param name="strPowerID">需要验证的权限ID</param>
        /// <returns>true:代表具有访问此权限</returns>
        public static bool checkpower(string strPowerID)
        {
            object oPowers = globalhelper.powerstring;
            if (oPowers != null)
            {
                return
                    stringhelper.findvalue(oPowers.tostr(), strPowerID, false)
                    || stringhelper.findvalue(oPowers.tostr(), "allmenuadmin", true);

                //allmenuadmin,这东东有什么意义？
                //[11-03-10 14:11 lxw]
            }
            else
            {
                throw new Exception("010:登陆超时，请重新登录!");
            }
        }

        /// <summary>
        /// 功能:通过权限验证HTML控件是否显示，用于控件的HTML标签里面
        /// [09.4.12 lxw]<para />
        /// </summary>
        /// <param name="strPowerID">需要验证的权限</param>
        /// <returns>返回控件是否显示和隐藏</returns>
        public static string display(string strPowerID)
        {
            if (string.IsNullOrEmpty(globalhelper.powerstring))
            {
                return " style='display:none!important;' ";
            }

            //用户具有此控件的访问权限
            if (checkpower(strPowerID))
            {
                return "";
            }

            return " style='display:none' ";
        }

        /// <summary>
        /// 验证gridview button 是否有效和无效
        /// </summary>
        /// <param name="Code"></param>
        /// <returns></returns>
        public static string checkbtn(string Code)
        {
            if (powerhelper.checkpower(Code))
            {
                return "false";
            }
            else
            {
                return "true";
            }
        }

    }
}
